<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/backstage/cl/common/wechatLibs.jsp"%>
<!doctype html>
<html>
<head>
<title>找礼包</title>
<meta charset="utf-8">
<meta name="viewport"
	content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection"
	content="telephone=no,email=no,date=no,address=no">
</head>
<body>
	<div class="main my-gift-bag">
		<ul id="bagList">

		</ul>
	</div>
	<!-- 底部菜单 -->
	<div class="h88 mt20"></div>
	<div class="bottom-nav">
		<ul>
			<li class="find-project"><a
				href="/bsc/wechat/findProject"> <i class="ico"></i>
					<span>找项目</span>
			</a></li>

			<li class="find-gift cur"><a
				href="/bsc/wechat/GobagList"> <i class="ico"></i> <span>找礼包</span>
			</a></li>

			<li class="mine"><a href="/bsc/wechat/Gohome">
					<i class="ico"></i> <span>我的</span>
			</a></li>
		</ul>
	</div>
</body>
<script type="text/javascript">
	var toast = new auiToast();
	var timeInterval;
	//页面初始化 
	$(function() {
		doSearch(0);
		timeInterval = window.clearInterval(timeInterval)
		timeInterval = self.setInterval("doSearch(0)", 60000);
	})
	function doSearch(clearStatus) {
		toast.loading({
			title : "数据加载中"

		})
		$.ajax({
			type : 'post',
			url : '/bsc/wechat/Gobag',
			dataType : 'json',
			success : function(data) {
				if (data) {

					createList(data)
				} else {
					alert("查询失败")
				}
				toast.hide();
			},
			error : function() {
				alert("网络异常")
				toast.hide();
			}
		})
	}
	//创建列表数据
	function createList(data) {
		var date=new Date().toLocaleDateString();
		//date.toLocaleDateString();
		var bagList = $("#bagList");
		var html = '';
			html = bagList.html();
		for (var i = 0; i < data.length; i++) {
			var row = data[i];
			var end;
			var soldout_time=row.soldout_time;
			var soldout=new Date(soldout_time).toLocaleDateString();
			if(date>soldout){
				end="已结束";
			}else{
				end=soldout;
			}
			var photo=row.cover_photo;
			var remain_num=row.remain_num;
			if(remain_num==null){
				remain_num=0;
			}else if(remain_num==""){
				remain_num=0;
			}
			html += '<li onclick="showBagDetail(' + row.bag_id + ')">'
			html += ' <div class="tit">' + row.bag_name + '</div>'
			html += ' <div  ></div>'
			html += ' <div class="box">'
			html += ' <div class="fl">'
			html += ' <span>只剩下'+remain_num+'了！ </span>'
			html += '<span>结束时间: '+end+'</span>'
			html += '</div>'
			html += '<div class="btn"> </div>'
			html += '</div>'
			html += '<img src="/bsc'+photo+'">'
			html += '</li>'
		}
		bagList.html(html);
	}
	function showBagDetail(bag_id) {
		window.location.href = '/bsc/wechat/GoshowBagDetail?bag_id='
				+ bag_id;
	}
</script>
</html>